import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class UDPEchosever {
    //创建服务端
    DatagramSocket socket;

    public UDPEchosever(int pase) throws SocketException {
        if (pase < 1024 || pase > 65535) {
            throw new RuntimeException("端口号不符合条件");
        }
        socket = new DatagramSocket(pase);
    }

    public void start(DatagramSocket socket) throws IOException {
        System.out.println("服务器已启动");
        while (true) {
            //接收用户发来的数据
            DatagramPacket datagramPacket = new DatagramPacket(new byte[1024], 1024);
            socket.receive(datagramPacket);
            //接收数据
            String request = new String(datagramPacket.getData(), 0, datagramPacket.getLength(), "UTF-8");
        }
    }
}
